from collections import OrderedDict

from django.shortcuts import render
from django.views import View

from apps.goods.models import GoodsChannel
from apps.goods.utils import get_categories
from apps.index.models import ContentCategory


class IndexView(View):
    def get(self,request):
        categories_dict = get_categories()
        # 广告数据
        contents = {}
        content_categories = ContentCategory.objects.all()
        for temp in content_categories:
            contents[temp.key] = temp.content_set.filter(status=True).order_by('sequence')
        # 渲染模板的上下文
        context = {
            'categories': categories_dict,
            'contents':contents,
        }
        return render(request,'index.html',context)
